package com.czl.module_storehouse.adapter;

import androidx.annotation.NonNull;


import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.czl.base.data.bean.tengyun.SortBean;
import com.czl.module_storehouse.R;
import com.lihang.ShadowLayout;

import java.util.List;

/**
 * @author xubin
 */
public class ReceiveAddPostAdapter extends BaseMultiItemQuickAdapter<SortBean, BaseViewHolder> {

    public static final int VIEW_TYPE_NOT_CHANGE = 0;
    public static final int VIEW_TYPE_CHANGE = 1;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public ReceiveAddPostAdapter(List<SortBean> data) {
        super(data);
        addItemType(VIEW_TYPE_NOT_CHANGE, R.layout.item_receive_details_post);
        addItemType(VIEW_TYPE_CHANGE, R.layout.item_receive_post_change);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, SortBean item) {
        int itemType = item.getItemType();
        if (VIEW_TYPE_CHANGE == itemType) {
            ShadowLayout shadowLayout = helper.getView(R.id.shadowLayout);
            shadowLayout.setShadowHiddenTop(getHeaderLayoutCount() != helper.getLayoutPosition());
            helper.setText(R.id.tv_change_num, "数量：" + item.getApplyNum())
                    .setText(R.id.tv_title, item.getSortName())
                    .setText(R.id.tv_model, "型号：" + item.getSortModel())
                    .setText(R.id.tv_num, String.valueOf(item.getReceiveCount()))
                    .setGone(R.id.iv_right, item.receiveNum() < 0)
                    .setGone(R.id.text_change, item.changeSort());
            helper.getView(R.id.text_change).setOnClickListener(v -> {
                if (getOnItemChildClickListener() != null) {
                    getOnItemChildClickListener().onItemChildClick(ReceiveAddPostAdapter.this, v, helper.getLayoutPosition());
                }
            });
            helper.getView(R.id.cl_root).setOnClickListener(v -> {
                /*if (item.receiveNum() == 0) {
                    return;
                }*/
                if (getOnItemChildClickListener() != null) {
                    getOnItemChildClickListener().onItemChildClick(ReceiveAddPostAdapter.this, v, helper.getLayoutPosition());
                }
            });
        } else {
            ShadowLayout shadowLayout = helper.getView(R.id.shadowLayout);
            shadowLayout.setShadowHiddenTop(getHeaderLayoutCount() != helper.getLayoutPosition());
            helper.setText(R.id.tv_apply_num, "申请数量：" + (item.getFirstFacilityCount() == null ? 0 : item.getFirstFacilityCount()))
                    .setText(R.id.tv_already_num, String.valueOf(item.getLendNum() == null ? 0 : item.getLendNum()))
                    .setText(R.id.tv_change_num, "待处理数量：" + item.getHandleNumInt())
                    .setText(R.id.tv_title, item.getSortName())
                    .setText(R.id.tv_model, "型号：" + item.getSortModel())
                    .setText(R.id.tv_num, String.valueOf(item.getReceiveCount()))
                    .setGone(R.id.iv_right, (item.getHandleNumInt() < 0))
                    .setGone(R.id.text_change, item.changeSort());
            helper.getView(R.id.text_change).setOnClickListener(v -> {
                if (getOnItemChildClickListener() != null) {
                    getOnItemChildClickListener().onItemChildClick(ReceiveAddPostAdapter.this, v, helper.getLayoutPosition());
                }
            });
            helper.getView(R.id.cl_root).setOnClickListener(v -> {
                /*if (item.receiveNum() == 0 || item.getHandleNumInt() == 0) {
                    return;
                }*/
                if (getOnItemChildClickListener() != null) {
                    getOnItemChildClickListener().onItemChildClick(ReceiveAddPostAdapter.this, v, helper.getLayoutPosition());
                }
            });
        }
    }
}
